﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<?php 
	//session_start();
	include_once("../DAO/DataHelper.php");
	include_once('../DAO/SanPhamDAO.php');
	include_once("../DAO/SanPhamDTO.php");
	include_once("../DAO/BinhLuanDTO.php");
?>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Mạng xã hội mua bán siêu việt | ShoppingHere.com</title>
		<link rel="stylesheet" href="../css/reset.css" type="text/css" />
		<link rel="stylesheet" href="../css/common.css" type="text/css" />
		<link rel="stylesheet" href="../css/home.css" type="text/css" />
		<script src="../scripts/jquery-1.5.2.min.js"></script>
		<script src="../scripts/common.js"></script>
		<link rel="stylesheet" href="../css/MenuMatic.css" type="text/css" media="screen" charset="utf-8" />
		<link rel="stylesheet" href="../css/MenuMatic2.css" type="text/css" media="screen" charset="utf-8" />
		<style type="text/css">
			#product-details .content {
				overflow: hidden;
			}
			
			#product-details .image-col img {
				-moz-border-radius: 5px;
				border-radius: 5px;
				width: 200px;
			}
			
			#product-details .image-col {
				float: left;
				margin-right: 10px;
				width: 200px;
			}
			
			#product-details .details-col {
				float: left;
				width: 500px;
			}
			
			#product-details .details-col p.name {
				font-weight: bold;
				font-size: 20px;
				margin-bottom: 10px;
			}
			
			#product-details .details-col p.price {
				margin-bottom: 5px;
				font-size: 15px;
			}
			
			#product-details .details-col p.shop {
				margin-bottom: 5px;
				font-size: 15px;
			}
			
			#product-details .details-col p.shop-owner {
				margin-bottom: 5px;
				font-size: 15px;
			}
			
			#product-details .details-col p.quantity {
				margin-bottom: 5px;
				font-size: 15px;
			}
			
			#product-details .details-col p.details {
				margin-bottom: 10px;
				margin-top: 10px;
				font-size: 15px;
			}
			
			#product-details .details-col p.tag {
				margin-bottom: 10px;				
			}
			
			#product-details .details-col input.quantity {
				margin-right: 10px;
			}
			
			#product-details .comment-zone {
				margin-top: 10px;
			}
			
			#product-details .comment-zone .comment-title {
				font-weight: bold;
				font-size: 15px;
				margin-bottom: 10px;
			}
			
			#product-details .comment-item {
				margin-left: 20px;
				margin-right: 20px;
				overflow: hidden;
				margin-top: 10px;
				margin-bottom: 10px;
			}
			
			#product-details .avatar-col img {
				width: 60px;
			}
			
			#product-details .avatar-col {
				float: left;
				margin-right: 10px;
				width: 60px;
			}
			.avatar-col img {
				width: 60px;
			}
			
			.avatar-col {
				float: left;
				margin-right: 10px;
				width: 60px;
			}
			
			.comment-info-col {
				float:none;
				/*width: 300px;*/
			}
			
			.comment-info-col .username {
				font-weight: bold;
				margin-bottom: 5px;
			}
			
			.comment-info-col .date {
				font-style: italic;
				margin-bottom: 5px;
			}
			
			.comment-box {
				margin-left: 20px;
			}
			
			.comment-box .comment-box-title {
				font-weight: bold;
				margin-bottom: 5px;
			}
			.comment-box textarea {
				width:680px;
				height: 60px;
			}
		</style>
	</head>
<?php

$masp = 1;
if(isset($_REQUEST['masp']))
{
	$masp=$_REQUEST['masp'];
}
else
{
	header("location: ../index.php");
}
$UserName = null;

$temp = SanPhamDAO::HienThiBinhLuanSanPham($masp);
?>					
<script type="text/javascript" language="javascript">
		var xmlhttp;
		var xmlhttp;
			function GetXmlHttpObject()
			{
				if (window.XMLHttpRequest)
				{
					// code for IE7+, Firefox, Chrome, Opera, Safari
					return new XMLHttpRequest();
				}
				if (window.ActiveXObject)
				{
					// code for IE6, IE5
					return new ActiveXObject("Microsoft.XMLHTTP");
				}
				return null;
			} 
		
		function BinhLuan($masp)
		{
			//var user = "lvhung";
			//alert($User);
			var NoiDung = document.getElementById('NoiDung').value;
			//document.getElementById('NoiDung').value ='';
			if(NoiDung != '')
			{
				xmlhttp=GetXmlHttpObject();
				xmlhttp.onreadystatechange=LoadBinhLuan;	
				var url="../DAO/BinhLuan.php?id=" + $masp + "&NoiDung=" + NoiDung;
				xmlhttp.open("get",url,true);
				xmlhttp.send(null);	
			}
			else
			{
				alert("Vui long nhap noi dung can binh luan !");
			}
		}
		
		function LoadBinhLuan()
		{
			if(xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var div=document.getElementById("BinhLuan");
				div.innerHTML=xmlhttp.responseText;
				
			}
		}
		
		
		function themVaoGioHang(masp,dongia,soluongcon)
			{
				
				//donvitinh=1;
				//soluongcon=1;
				var soluong=document.getElementById("txtSoLuong").value;
				var donvitinh=document.getElementById("label").innerHTML;
				//alert(donvitinh);
				if(soluong=="")
				{
					alert("Chưa nhập số lượng cần mua");
					return;
				}
				var test=kiemTraLaSo(soluong);
			//	alert(test);
				if(test==false)
				{
					alert("Số lượng cần mua phải là số nguyên");
					return;
				}
				/*if(soluong>soluongcon)
				{
					alert("Số lượng bạn mua lớn, xin liên hệ trực tiếp với chúng tôi để được đáp ứng tốt nhất");
					return;
				}*/
				//Kiem tra so luong la so ?
				xmlhttp=GetXmlHttpObject();
				xmlhttp.onreadystatechange=showThem;
				var serverUrl="../BUS/xlGioHangBUS.php?masp="+masp+"&type=1&soluong="+soluong +"&dongia="+dongia+"&donvitinh="+donvitinh+"&soluongcon="+soluongcon;
				xmlhttp.open("get",serverUrl,"true");
				xmlhttp.send(null);
				
			}
			function kiemTraLaSo(so)
			{
				var n=so.length;
				for( var i=0;i<n;i++)
				{
					if(so[i]<"0" || so[i]>"9")
					{
						return false;
						
					}
				}
				return true;
			}
			function showThem()
			{
				if(xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					var result=xmlhttp.responseText;
					
					//alert(result);
					//document.getElementById("ls").innerHTML=result;
					if(result=="true")
					{
						alert("Đã thêm vào giỏ hàng");
					}
					
				}
			}
</script>


	<body>
		<div id="page">
			<?php
				require("../webconfig.php");
				//require("../DAO/DataHelper.php");
				require("../UserControl/header.php");
				include_once("../DAO/DanhMucSanPham_DAO.php");
			?>

			<div id="content">
				<div id="shop-banner">
					<img src="../temp/shop-banner.jpg" />
				</div>
				<?php
					require("../UserControl/DanhMucLoaiSanPham.php");
				?>
				<div id="seller-shop-info" class="block layout-2col-col2" style="width:830px"> 
					<div class="title">
					  <h3>Xem chi tiết sản phẩm</h3>
				  </div>
					<div class="content">
						
 						<div id="product-details" class="block layout-2col-col2">
				
				<div class="content">
<?php
//$masp = "1";
$result = SanPhamDAO::ChiTietSanPham($masp);
?>		
					<div class="image-col">
						<img src="../images/<?php echo $result->sp_hinh_anh;?>" />
					</div>
					<div class="details-col">
						<p class="name"><?php echo $result->sp_ten;?></p>
						<p class="price">
						  <label>Giá : </label>
						  <span><?php echo $result->sp_don_gia;?> VND</span><p>
						<p class="shop">
						  <label>Shop : </label>
						  <span><a ><b><?php echo $result->sp_ten_gian_hang;?></b></a></span></p>
						<p class="shop-owner">
						  <label>Chủ shop : </label>
						  <span><a ><?php echo $result->sp_chu_gian_hang;?></a></span></p>
						<p class="quantity">
						  <label>Số lượng còn : </label>
						  <span> <?php echo"<label> $result->sp_so_luong </label><label id='label'>$result->sp_don_vi_tinh</label>"?></span></p>
						<p class="details">
						  <label>Mô tả : <br/>
						  </label><span>
							<?php echo $result->sp_mo_ta;?>
							</span>
						</p>
						<p class="tag">
						  <label>Từ khóa : </label>
						  <span><a href="#">laptop</a> <a href="#">dell</a> <a href="#">electronic</a> <a href="#">compter</a> <a href="#">digital</a></span></p>
						<label>Số lượng cần mua : </label>
						<input type="text" id="txtSoLuong" class="tb quantity" /><input type="button" class="buy btn" <?php echo"onClick='themVaoGioHang($result->sp_ma,$result->sp_don_gia,$result->sp_so_luong);'"?> value="Mua" />
						
						
					</div>
				</div>
				<div class="comment-zone">
							<p class="comment-title">
								Bình luận
							</p>

							<div id= "BinhLuan">
							<?php
							if(count($temp)>0)
							{
							for($i = 0 ; $i < count($temp) ; $i++)
							{
								$row = $temp[$i];
							?>
								<div class="comment-item">
									<div class="avatar-col">
										<img src="../images/<?php echo $row->tk_avatar;?>" />
									</div>
									<div class="comment-info-col">
										<p class="username"><b>Người bình luận : </b><a ><?php echo $row->blsp_username;?></a></p>
										<p class="date">Ngày Đăng :<?php echo $row->blsp_ngay_tao;?></p>
										<p class="comment">Nội dung :<?php echo $row->blsp_noi_dung;?></p>
									</div>								
								</div>
							<?php
								}
							}
							?>
							</div>
							<?php
								if(isset($_SESSION['IsLogin'])&& isset($_SESSION['UserName']))
								{
									if($_SESSION['IsLogin']==true)
									{
									$UserName = $_SESSION['UserName'];
									echo("
										<div class='comment-box'>
											<p class='comment-box-title'>Đăng bình luận</p>
											<div>
											<textarea name='NoiDung' id = 'NoiDung'></textarea>
											</div>
											<div align='center'>
											<td><br/></td>
											<input class='buy btn' type='button' value='Bình luận' onClick='BinhLuan($masp)'/>
											</div>
										</div>
									</div>");
									}
									else
									{
										echo("<p style='color:red;font-weight:bold'>Đăng nhập để bình luận</p>");
		
									}
								}
								else
								{
									echo("<p style='color:red;font-weight:bold'>Đăng nhập để bình luận</p>");
								}
							?>
			</div>
					</div>
				</div>
				
				
				<div id="ls">
				</div>
			</div>
			<?php
				require("../UserControl/footer.php");
			?>
		</div>
	</body>
</html>
